/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef IMAGE_KNIFE_C_KEKE_IMAGE_DATA_H
#define IMAGE_KNIFE_C_KEKE_IMAGE_DATA_H

#include <multimedia/image_framework/image/pixelmap_native.h>

namespace ImageKnifePro {
/**
 * @brief 单帧或多帧的pixelmap图片数据, 管理原始OH_PixelmapNative释放
 * 图片数据pixelmap用于构造ImageData后，不要再去手动释放pixelmap内存，以免造成双重释放的问题。
 */
struct ImageData {
public:
    /**
     * @brief 构造单帧的pixelmap图片数据
     * @param pixelmap : 原始OH_PixelmapNative对象指针
     */
    explicit ImageData(OH_PixelmapNative *pixelmap);

    /**
     * @brief 构造多帧的pixelmap图片数据
     * @param pixelmapList : pixelmap数组
     * @param delayTimeList : 每帧图片对应播放时间数组,单位毫秒
     * @param frameCount : 图片总帧数
     */
    ImageData(OH_PixelmapNative **pixelmapList, int *delayTimeList, size_t frameCount);

    /**
     * @brief 获取单帧图片的pixelmap地址
     * @return pixelmap地址
     */
    OH_PixelmapNative *GetPixelmap() const;

    /**
     * @brief 获取动图pixelmap数组
     * @return pixelmap数组地址
     */
    OH_PixelmapNative **GetPixelmapList() const;

    /**
     * @brief 获取每帧图片播放时长数组
     * @return 播放时长数组，单位毫秒
     */
    int *GetDelayTimeList() const;

    /**
     * @brief 获取图片的总帧数
     * @return 图片帧数
     */
    uint32_t GetFrameCount() const;
    
    ~ImageData();

    ImageData(const ImageData&) = delete;
    ImageData& operator = (const ImageData&) = delete;
private:
    // 禁止修改图片数据地址，防止错误析构和内存泄漏
    OH_PixelmapNative **pixelmapList_ = nullptr;
    int *delayTimeList_ = nullptr;
    uint32_t frameCount_ = 0;
};

}

#endif // IMAGE_KNIFE_C_KEKE_IMAGE_DATA_H
